/**
 * Copyright (c) 2024,  科泰集团教研团队
 * 版权所有，请勿侵权
 */
package utils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 科泰集团教研团队
 * @version 1.0.0
 * @fileName Page.java
 */
public class Page<T> {
	// 当前页码，默认为第1页
	private Integer pageNo = 1;
	// 每页数量，默认10条/页
	private Integer pageSize = 3;
	// 总数据量，如果未设置默认为null
	private Integer totalCount = null;
	// 总页数
	private Integer totalPageCount = 1;
	// 分页数据集合
	private List<T> data = new ArrayList<>();

	public Integer getPageNo() {
		return pageNo;
	}

	public void setPageNo(Integer pageNo) {
		if(pageNo <= 0){
			pageNo = 1;
		}
		if(totalCount != null){
			// 计算过总页数后，页码的设置要参考总页数
			if(totalPageCount >= 1 && pageNo > totalPageCount){
				pageNo = totalPageCount;
			}
		}
		this.pageNo = pageNo;
	}

	public Integer getPageSize() {
		return pageSize;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}

	public Integer getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(Integer totalCount) {
		this.totalCount = totalCount;
		this.totalPageCount = this.totalCount % this.pageSize == 0
				? this.totalCount / this.pageSize
				: this.totalCount / this.pageSize + 1;
	}

	public Integer getTotalPageCount() {
		return totalPageCount;
	}
	public void setTotalPageCount(Integer totalPageCount) {
		this.totalPageCount = totalPageCount;
	}

	public List<T> getData() {
		return data;
	}

	public void setData(List<T> data) {
		this.data = data;
	}

}